﻿using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using StockholmsStad.Windows.UI.Infrastructure;
using StockholmsStad.Windows.UI.Modules.MainModule.Interfaces;
using StockholmsStad.Windows.UI.Modules.MainModule.Views;
using StockholmsStad.Windows.UI.Modules.MainModule.Presenters;
using StockholmsStad.Windows.UI.Modules.MainModule.Controllers;
using StockholmsStad.Windows.UI.Modules.MainModule.Services;

namespace StockholmsStad.Windows.UI.Modules.MainModule
{
    public class MainModule : IModule
    {
        private readonly IUnityContainer container;
        private readonly IRegionManager regionManager;

        public MainModule(IUnityContainer container, IRegionManager regionManager)
        {
            this.container = container;
            this.regionManager = regionManager;
        }

        #region IModule Members

        public void Initialize()
        {
            container.RegisterType<IViewController, ViewController>(new ContainerControlledLifetimeManager());
            container.RegisterType<IToolBarService, ToolBarService>(new ContainerControlledLifetimeManager());

            container.RegisterType<IMenuView, MenuView>();
            container.RegisterType<IToolBarView, ToolBarView>();
            
            //var menuPresenter = container.Resolve<MenuPresenter>();
            var toolBarPresenter = container.Resolve<ToolBarPresenter>();

            //var menuRegion = regionManager.Regions[RegionNames.MenuRegion];
            var toolBarRegion = regionManager.Regions[RegionNames.ToolBarRegion];

            //menuRegion.Add(menuPresenter.View);
            toolBarRegion.Add(toolBarPresenter.View);
        }

        #endregion
    }
}
